<template>
	<view class="whitePage">
		<u-navbar :title="`${formData.sign ? '编辑' : '新增'}医生`" autoBack placeholder />
		<view class="flex u-border-bottom">
			<view>手机号：</view>
			<u--input
				placeholder="请输入手机号"
				border="none"
				v-model="formData.mobile"
				:disabled="formData.sign"
				:customStyle="{height: '70rpx', paddingLeft: '30rpx', marginLeft: '30rpx'}"
			/>
		</view>
		<view class="title">负责门店</view>
		<u-radio-group v-model="formData.storeSign">
			<u-radio shape="square" v-for="(item, index) in shopList" :key="index" :name="item.sign" :label="item.name" />
		</u-radio-group>
		<view class="fixBottomBtn" @click="confirm">保存</view>
	</view>
</template>

<script>
import { addDoctor, getDoctor, editDoctor } from '@/api/doctor.js';
import { adminShopList } from '@/api/store.js';
export default {
	data() {
		return {
			shopList: [],
			formData: {}
		}
	},
	onLoad(eve) {
		adminShopList().then(res => this.shopList = res)
		if(!eve.sign) return
		getDoctor({sign: eve.sign}).then(res => {
			this.formData = res
			this.formData.sign = eve.sign
		})
	},
	methods: {
		// 保存信息
		confirm() {
			if(this.formData.sign) {
				editDoctor(this.formData).then(res => uni.navigateBack())
			} else {
				addDoctor(this.formData).then(res => uni.navigateBack())
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.whitePage {
	padding: 0 20rpx;
}
.u-border-bottom {
	padding: 40rpx 0;
}
::v-deep .u-radio {
	margin-right: 40rpx;
	margin-bottom: 40rpx;
}
.title {
	font-size: 35rpx;
	margin: 40rpx 0;
}
</style>
